package com.jie.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RespBean<T> {
    private long code;
    private String message;
    private Object data;
    /**
     * 成功返回结果
     * @return
     */
    public static RespBean success(){
        return new RespBean(200,null,null);
    }
    /**
     * 成功返回结果
     *
     * @param message
     * @return
     */
    public static <T> RespBean success(String message){
        return new RespBean(ResponseCode.SUCCESS.getCode(), message,null);
    }

    /**
     * 成功返回结果
     *
     * @param message
     * @param data
     * @return
     */
    public static <T> RespBean success(String message, Object data){
        return new RespBean(ResponseCode.SUCCESS.getCode(),message,data);
    }

    /**
     * 失败返回结果
     *
     * @param message
     * @return
     */
    public static <T> RespBean error(String message){
        return new RespBean(ResponseCode.ERROR.getCode(),message,null);
    }

    /**
     * 失败返回结果
     *
     * @param message
     * @param data
     * @return
     */
    public static <T> RespBean error(String message, Object data){
        return new RespBean(ResponseCode.ERROR.getCode(),message,data);
    }
    public static <T> RespBean error(Integer code,String message){
        return new RespBean(code,message,null);
    }
}
